package com.sskj.gcc.ui.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.gcc.R;
import com.sskj.gcc.bean.game.GameGetFoodBean;
import com.sskj.gcc.presenter.game.GameFragmentPresenter;
import com.sskj.gocoin.common.Constants;
import com.sskj.gocoin.common.adapter.BaseRecyclerAdapter;
import com.sskj.gocoin.common.adapter.RecyViewHolder;
import com.sskj.gocoin.mine.MyShareActivity;
import com.sskj.gocoin.mine.VerifyHomeActivity;
import com.sskj.gocoin.v.activity.SecurityCenterActivity;
import com.sskj.gocoin.v.activity.WebActivity;

import java.util.ArrayList;

import butterknife.BindView;

public class GameBottomFoodFragment extends GameBaseFragment {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private BaseRecyclerAdapter<GameGetFoodBean.Bean> mAdapter;
    ArrayList<GameGetFoodBean.Bean> arrayList;

    @Override
    public int getLayoutId() {
        return R.layout.app_fragment_game_food;
    }

    @Override
    public GameFragmentPresenter getPresenter() {
        return new GameFragmentPresenter();
    }

    @Override
    public void initView() {
        arrayList = new ArrayList();
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mAdapter = new BaseRecyclerAdapter<GameGetFoodBean.Bean>(getActivity(), R.layout.app_adapter_game_food) {
            @Override
            public void convert(RecyViewHolder holder, GameGetFoodBean.Bean data, int position) {

                if (position % 3 == 0) {
                    GradientDrawable background = new GradientDrawable();
                    background.setCornerRadius(10);
                    background.setColor(Color.parseColor("#8346FD"));
                    holder.getView(R.id.iv_background).setBackground(background);
                    holder.setTextColor(R.id.tv_buy, Color.parseColor("#8346FD"));
                    Glide.with(getActivity()).load(R.drawable.image_game_food_1).into((ImageView) holder.getView(R.id.iv_logo));
                } else if (position % 3 == 1) {
                    GradientDrawable background = new GradientDrawable();
                    background.setCornerRadius(10);
                    background.setColor(Color.parseColor("#FE4F56"));
                    holder.getView(R.id.iv_background).setBackground(background);
                    holder.setTextColor(R.id.tv_buy, Color.parseColor("#FE4F56"));
                    Glide.with(getActivity()).load(R.drawable.image_game_food_2).into((ImageView) holder.getView(R.id.iv_logo));
                } else if (position % 3 == 2) {
                    GradientDrawable background = new GradientDrawable();
                    background.setCornerRadius(10);
                    background.setColor(Color.parseColor("#00CBBA"));
                    holder.getView(R.id.iv_background).setBackground(background);
                    holder.setTextColor(R.id.tv_buy, Color.parseColor("#00CBBA"));
                    Glide.with(getActivity()).load(R.drawable.image_game_food_3).into((ImageView) holder.getView(R.id.iv_logo));
                }

                holder.setText(R.id.tv_name, data.getName());
                holder.setText(R.id.tv_content, data.getMsg());

                if ("1".equals(data.getStatus())) {
                    holder.setText(R.id.tv_buy, data.getButton());
                } else if ("2".equals(data.getStatus())) {
                    holder.setText(R.id.tv_buy, getString(R.string.strMainActivityGame00025));
                } else if ("3".equals(data.getStatus())) {
                    holder.setText(R.id.tv_buy, getString(R.string.strMainActivityGame00026));
                }

                ClickUtil.click(holder.getView(R.id.tv_buy), new ClickUtil.Click() {
                    @Override
                    public void click() {
                        if ("1".equals(data.getStatus())) {
                            if ("邀请好友".equals(data.getName())) {
                                startActivity(new Intent(getActivity(), MyShareActivity.class));
                            } else if ("实名认证".equals(data.getName())) {
                                startActivity(new Intent(getActivity(), VerifyHomeActivity.class));
                            } else if ("科普知识".equals(data.getName())) {
                                startActivity(new Intent(getActivity(), WebActivity.class).putExtra(Constants.INTENT_TYPE, "15"));
                            }
                            getActivity().finish();
                        } else if ("2".equals(data.getStatus())) {
                            // 1 实名认证 2 科普知识 3邀请好友
                            if ("邀请好友".equals(data.getName())) {
                                mPresenter.getTask("3");
                            } else if ("实名认证".equals(data.getName())) {
                                mPresenter.getTask("1");
                            } else if ("科普知识".equals(data.getName())) {
                                mPresenter.getTask("2");
                            }
                        }
                    }
                });
            }
        };
        recyclerView.setAdapter(mAdapter);
        mPresenter.getTaskList();
    }

    @Override
    public void getTaskListSuccess(GameGetFoodBean data) {
        super.getTaskListSuccess(data);
        arrayList.clear();
        arrayList.add(data.getR1());
        arrayList.add(data.getR2());
        arrayList.add(data.getR3());
        mAdapter.setDatas(arrayList);
    }

    @Override
    public void getTaskSuccess(String data) {
        super.getTaskSuccess(data);
        ToastUtil.showShort(data);
        getActivity().finish();
    }
}
